<template>
  <div class="gdMap">
      <div class="box">
        <input type="text" class="gdInput" placeholder="请输入关键字" v-model="keyWords" @input="inpChange">
         <scroll-view
          scroll-y
          scroll-with-animation
          class="gdContent"

          >
          <div class="result" v-for="(item , index) in result" :key="index"  @click="getKeyword(item)">
            {{item.name}}
          </div>
        </scroll-view>
      </div>
      <div class="showMap">
        <div class="title">显示当前位置 : </div>
        <map
          :longitude="longitude"
          :latitude="latitude"
          scale="16"
          :markers="markers"
          @tap="maptap"
          class="map">
        </map>

    </div>
  </div>
</template>

<script>
import amapFile from "../../utils/amap-wx";
export default {
  data(){
    return{
      longitude:0,
      latitude:0,
      markers:[],
      // 获取到的数据
      result:[],
      keyWords:''
    }
  },
  methods:{
    getMap(){
        const _this = this
        const map =new amapFile.AMapWX({key:'6b38a77573ebc1ecfbfc03cffa396a00'})
        map.getRegeo({
          iconPath:'/static/images/marker.png',
          iconWidth:22,
          iconHeight:32,
          
          success: function(data){
            let res = data[0]
            //成功回调
           let marker = [{
             id:res.id,
             latitude:res.latitude,
             longitude:res.longitude,
             width:res.width,
             height:res.height
           }]
           _this.markers = marker
           _this.longitude = res.longitude
           _this.latitude = res.latitude
          },
          fail: function(info){
            //失败回调
            console.log(info)
          }
      })      
    },
    inpChange(e){
      var _this = this
      const map =new amapFile.AMapWX({key:'6b38a77573ebc1ecfbfc03cffa396a00'})
      map.getInputtips({
        keywords:_this.keyWords,
        location:'',
        success:function(data){
          
          _this.result = data.tips
        }
      })

    },
    markers(){

    },
    getKeyword(item){
      this.$store.commit('ChangeCity',{cityName:item})
      wx.navigateBack({
        delta: 1 //返回的页面数，如果 delta 大于现有页面数，则返回到首页,
      });

    }
    
  },
  mounted(){
    this.getMap()
  }
}
</script>

<style lang="less" scope>
@import './index.less';
</style>